app.service('shopService',['$q','utilService',function($q,utilService){
    var _this_=this;

    //查询商品列表
    _this_.sendAuthCode= function ($scope) {
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + '/shop/code/'+$scope.systemUserAddVO.mobilePhone,
            method:"POST"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }


    //发送请求回后台获取地区数据
    _this_.findArea=function($scope,level,parentId){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain+"area/info",
            params:{level:level,parentId:parentId}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //查询行业
    _this_.getIndustryFullName = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/get/industry/list'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }

    //查询套餐
    _this_.getSetMealList = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'set/meal/list',
            params:$scope.setMealVO
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    //添加店铺
    _this_.addShop = function($scope){

        var systemUserAddVOStr=JSON.stringify($scope.systemUserAddVO);
        var shopAddVOStr=JSON.stringify($scope.shopAddVO);
        var formData={systemUserAddVOStr:systemUserAddVOStr,shopAddVOStr:shopAddVOStr,setMealId:$scope.setMealId};
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'shop',
            data:formData,
            method:"POST"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };

    //查询门店信息
    _this_.queryShop = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + '/shop/info/id',
            params:{id:$scope.shopEditVO.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    };

    //修改店铺信息
    _this_.editShop = function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'shop/edit/info',
            data:$scope.shopEditVO,
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };
}]);